﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>
<%@ Import Namespace="TarreOA.TarreOAModels  " %>

<script runat="server">

    private int cgid;

    protected void BtnCreateGroup_Click(object sender, EventArgs e)
    {
        if(ViewState["cgid"] != null)
        {
            cgid = (int) ViewState["cgid"];
        }
        Response.Redirect("AppendGroupLinkMan.aspx?cgid=" + cgid.ToString());
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            if(Request["cgid"] != null)
            {
                cgid = int.Parse(Request["cgid"]);
                this.DataList_DataTable();
                ViewState["cgid"] = cgid;
            }
        }
    }

    protected void DataList_DataTable()
    {
        UserCommunicationGroupLinkMantbService ucgLinkMantbService = new UserCommunicationGroupLinkMantbService();
        List<UserCommunicationGroupLinkMantb> list = ucgLinkMantbService.findByComGroupId(cgid);
        if(list != null && list.Count > 0)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt.Columns.Add("GroupLinkManId", typeof(string));
            dt.Columns.Add("GroupLinkManName", typeof(string));
            dt.Columns.Add("GroupLinkManHandset", typeof(string));
            dt.Columns.Add("GroupLinkManSec", typeof(string));
            dt.Columns.Add("GroupLinkManUnitTelephone", typeof(string));
            dt.Columns.Add("GroupLinkManEmail", typeof(string));
            foreach(UserCommunicationGroupLinkMantb ucgLinkMan in list)
            {
                DataRow dr = dt.NewRow();
                dr["GroupLinkManId"] = ucgLinkMan.GroupLinkManId.ToString();
                dr["GroupLinkManName"] = ucgLinkMan.GroupLinkManName;
                dr["GroupLinkManHandset"] = ucgLinkMan.GroupLinkManHandset;
                dr["GroupLinkManSec"] = ucgLinkMan.GroupLinkManSec == 0 ? "男" : "女";
                dr["GroupLinkManUnitTelephone"] = ucgLinkMan.GroupLinkManUnitTelephone;
                dr["GroupLinkManEmail"] = ucgLinkMan.GroupLinkManEmail;
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            this.DataList1.DataSource = ds.Tables[0].DefaultView;
            this.DataList1.DataBind();
        }
        else
        {
            this.DataList1.DataSource = null;
            this.DataList1.DataBind();
        }
    }

    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string cgLinkManId = ((HtmlInputHidden) e.Item.FindControl("HidLinkManId")).Value;
            ((HyperLink) e.Item.FindControl("HylInfo")).Attributes.Add("cgLinkManId", cgLinkManId);
            ((HyperLink) e.Item.FindControl("HylInfo")).NavigateUrl = "javascript:openLinkManInfoDialogWindow('" + cgLinkManId + "')";
            //((HyperLink)e.Item.FindControl("HylEdit")).Attributes.Add("cgLinkManId", cgLinkManId);
            ((HyperLink) e.Item.FindControl("HylEdit")).NavigateUrl = "UpdateGroupLinkManInfo.aspx?cgLmid=" + cgLinkManId;
            ((LinkButton) e.Item.FindControl("LbtDelete")).Attributes.Add("cgLinkManId", cgLinkManId);
            ((LinkButton) e.Item.FindControl("LbtDelete")).Attributes.Add("onclick", "return confirm('您确认删除此联系人吗？')");
        }
    }

    protected void LbtDelete_Click(object sender, EventArgs e)
    {
        if(ViewState["cgid"] != null)
        {
            cgid = (int) ViewState["cgid"];
        }
        int cgLinkManId = int.Parse(((LinkButton) sender).Attributes["cgLinkManId"]);
        UserCommunicationGroupLinkMantbService ucgLinkManService = new UserCommunicationGroupLinkMantbService();
        ucgLinkManService.delComGroupLinkManByGroupLinkManId(cgLinkManId);
        this.DataList_DataTable();
        ViewState["cgid"] = cgid;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <script type="text/javascript" src="../../js/UserCommunication.js"></script>
    <link rel="Stylesheet" type="text/css" href="../../Styles/right_style.css" />
    <script type="text/javascript" src="../../Scripts/jquery.ui/js/jquery.js"></script>


    <style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>

</head>
<body>
    <form id="form1" runat="server">
        <div class="sub_right_top">
            <div class="add_book_right">
      <div class="add_book_new">
      <span class="add_book_newword" style="text-align: left">
        <asp:Button ID="BtnCreateLinkman" runat="server" OnClick="BtnCreateGroup_Click" Text="新建联系人"
                            Width="125px" />
                            </span></div>
      <div class="add_book_guanli" align="left">
          <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Italic="True"
                                Text="管理联系人" Width="111px"></asp:Label>
                                </div>

        <asp:Repeater ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
                            <HeaderTemplate>
                            <table width="99%" border="1" cellpadding="0" cellspacing="0" bordercolor="#72b0d8" style="border-collapse:collapse; ">
                                    <tr bgcolor="#b1d5ef">
                                        <td>姓名</td>
                                        <td>性别</td>
                                        <td>单位电话</td>
                                        <td>手机号码</td>
                                        <td>电子邮件</td>
                                        <td>操作</td>
                                  </tr>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <asp:Label ID="LblLinkManName" runat="server" Text='<%# Eval("GroupLinkManName") %>'></asp:Label></td>
                                    <td>
                                        <asp:Label ID="LblLinkManSec" runat="server" Text='<%# Eval("GroupLinkManSec") %>'></asp:Label></td>
                                    <td>
                                        <asp:Label ID="LblLinkManUnitTelephone" runat="server" Text='<%# Eval("GroupLinkManUnitTelephone") %>'></asp:Label></td>
                                    <td>
                                        <asp:Label ID="LblHandset" runat="server" Text='<%# Eval("GroupLinkManHandset") %>'></asp:Label></td>
                                    <td>
                                        <asp:Label ID="LblLinkManEmail" runat="server" Text='<%# Eval("GroupLinkManEmail") %>'></asp:Label>
                                    </td>
                                    <td>
                                        <asp:HyperLink ID="HylInfo" runat="server" Font-Underline="false">详情</asp:HyperLink>
                                        <asp:HyperLink ID="HylEdit" runat="server" Font-Underline="false">编辑</asp:HyperLink>
                                        <asp:LinkButton ID="LbtDelete" runat="server" Font-Underline="False" OnClick="LbtDelete_Click">删除</asp:LinkButton></td>
                                </tr>
                                <input id="HidLinkManId" runat="server" type="hidden" value='<%# Eval("GroupLinkManId") %>' />
                            </ItemTemplate>
                            <FooterTemplate>
                                </table>
                            </FooterTemplate>
                        </asp:Repeater>
        </div>
        </div>
    </form>
</body>
</html>
